package com.example.htmlfx.component;

import javafx.beans.InvalidationListener;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.control.CheckBox;

/**
 * 多选框组件
 *
 * @author gzkemays
 * @date 2021/8/4
 */
public class CheckBoxComponent {
  CheckBox checkBox = new CheckBox();

  public ObservableValue<CheckBox> getCheckBox() {
    return new ObservableValue<CheckBox>() {
      @Override
      public void addListener(ChangeListener<? super CheckBox> listener) {}

      @Override
      public void removeListener(ChangeListener<? super CheckBox> listener) {}

      @Override
      public CheckBox getValue() {
        return checkBox;
      }

      @Override
      public void addListener(InvalidationListener listener) {}

      @Override
      public void removeListener(InvalidationListener listener) {}
    };
  }

  public Boolean selected() {
    return checkBox.isSelected();
  }

  public void getSelected() {
    checkBox.setSelected(true);
  }

  public void noSelected() {
    checkBox.setSelected(false);
  }
}
